package net.huashitong.oversee.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.oversee.dao.CoordinateDao;
import net.huashitong.oversee.dao.GradePointDao;
import net.huashitong.oversee.entity.*;
import net.huashitong.oversee.filter.CoordinateFilter;
import net.huashitong.oversee.filter.GradePointFilter;
import net.huashitong.oversee.web.QuestionReport;
import net.huashitong.user.databean.BnpUserDatabean;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.service.BnpUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

//问题处理
@Service
public class CoordinateService extends StringPKService<Coordinate> {

    @Autowired
    private CoordinateDao dao;
    @Autowired
    private SysTableService tableService;
    @Autowired
    private FeedBackLeaderService feedservice;
    @Autowired
    private BnpUserService bnpUserService;


    @Override
    protected BaseDao<Coordinate, String> getDao() {
        return dao;
    }

    protected void beforeSave(Coordinate obj) {
        obj.setSysId(tableService.updateMaxSysId("t_question", null));
    }

    Logger log = LoggerFactory.getLogger(CoordinateService.class);

    public List<Coordinate> queryAll(CoordinateFilter filter) {
        return dao.queryAllCoordinate(filter);
    }


    //条件搜索
    public List<Coordinate> queryCoordinate(CoordinateFilter filter) {
        return dao.queryCoordinate(filter);
    }

    public int queryCoordinateCount(CoordinateFilter filter) {
        return dao.queryCoordinateCount(filter);
    }

    //条件搜索(查看是否存在)
    public List<Coordinate> queryCoordinates(CoordinateFilter filter) {
        return dao.queryCoordinates(filter);
    }

    //我的问题
    public int getMyquestion(BnpUser user) {
        return dao.getMyQusetion(user).size();
    }


    //获取所有涉及单位
    public List<BnpUserDatabean> queryAllInvolveUnit() {
        BnpUserFilter filter = new BnpUserFilter();
        filter.setBranchType("4");
        List<BnpUser> userList = bnpUserService.queryUserInfo2(filter);
        List<BnpUserDatabean> deptLists = new ArrayList<>();
        for (BnpUser bnpUser : userList) {
            BnpUserDatabean bnpUserDatabean = new BnpUserDatabean();
            bnpUserDatabean.setBranch(bnpUser.getBranch());
            deptLists.add(bnpUserDatabean);
        }
        return deptLists;
    }


    public void sendMessage(Coordinate coordinate) {
        String msg = "【重大项目节点管理】您好,项目:<" + coordinate.getProjectName() + ">新增一条需协调事项,协调事项为:<" + coordinate.getHelpInfo() + ">请登录查看详情,并及时处理。系统地址：https://www.fzzhengxinyun.com ，帐号为个人手机号，初始密码123456";
        msg = msg.replace("政府", "");
        msg = msg.replace("逾期", "超期");
        int code = 99;
        //责任人号码
        code = feedservice.QuesttionSendMsg(msg, coordinate.getResUserPhone());
        if (0 == code) log.info("---责任人发送成功 ---");
        //负责人号码
        feedservice.QuesttionSendMsg(msg, coordinate.getBossPhone());
        if (0 == code) log.info("---负责人发送成功 ---");
        //经办人
        feedservice.QuesttionSendMsg(msg, coordinate.getOperatorPhone());
        if (0 == code) log.info("---经办人发送成功 ---");
        //分管县领导
        feedservice.QuesttionSendMsg(msg, coordinate.getfGcountyLeaderPhone());
        log.info("---分管县领导发送成功 ---");
    }
}
